package com.lr.springbootdemo.service;

import com.lr.springbootdemo.bean.People;
import com.lr.springbootdemo.repositories.PeopleRepository;
import com.lr.springbootdemo.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * .
 * Created by li.rui on 2016-06-12.
 */
@Service
public class DemoService{
    private static Logger logger = LoggerFactory.getLogger(DemoService.class);
    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    @Autowired
    private PeopleRepository peopleRepository;

    public Object getList(){
        return jdbcTemplate.queryForList("select * from people",new HashMap<String, Object>());
    }

    public Object testRepository(People people){
//        logger.info(JsonUtil.object2String(peopleRepository.findByNameAndSex("xiaoming","man")));
//        logger.info(JsonUtil.object2String(peopleRepository.findAll()));
        logger.info(JsonUtil.object2String(peopleRepository.findOne(1)));
        logger.info("************************************");
        logger.info(JsonUtil.object2String(peopleRepository.save(people)));
//        peopleRepository.delete(people);
//        logger.info(JsonUtil.object2String(peopleRepository.exists(1)));

        return null;
    }

}
